package com.ioidea.common.view

import android.app.Activity
import android.content.Context
import android.graphics.Color
import android.os.Bundle
import android.view.LayoutInflater
import androidx.annotation.ColorInt
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.WindowCompat
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.lifecycleScope
import androidx.viewbinding.ViewBinding
import com.ioidea.base.dialog.LoadingDialog
import com.ioidea.base.util.StatusBarUtil
import kotlinx.coroutines.CoroutineScope
import java.lang.reflect.ParameterizedType

abstract class BaseActivity<VB : ViewBinding> : AppCompatActivity() {
    protected lateinit var binding: VB
     val mContext: Context
        get() = this

     val mLifecycleOwner: LifecycleOwner
        get() = this

     val scope: CoroutineScope
        get() = lifecycleScope


    @Suppress("UNCHECKED_CAST")
    override fun onCreate(savedInstanceState: Bundle?) {
        val type = javaClass.genericSuperclass as ParameterizedType
        val clazz0 = type.actualTypeArguments[0] as Class<VB>
        val method = clazz0.getMethod("inflate", LayoutInflater::class.java)
        binding = method.invoke(null, layoutInflater) as VB
        setContentView(binding.root)
        super.onCreate(savedInstanceState)
        initTopBar()
        init()


    }

    protected open fun isImmersiveTopBar(): Boolean {
        return true
    }

    protected open fun initTopBar() {
        if (isImmersiveTopBar()) {
            StatusBarUtil.immersive(this)
            StatusBarUtil.darkMode(this)
        }

    }



    abstract fun init()


}